Welcome to the hexadecimal and binary guide. This guide is aimed at people who are starting out ROM Hacking, but people who aren't interested in ROM Hacking can still read the guide to learn hexadecimal and binary. In this guide I assume the reader has no previous knowledge on binary or hexadecimal. I start out by teaching you about binary and how it works, followed by a lesson on hexadecimal, and then I will show you how to work with binary and hexadecimal in the Windows Calc.exe program, in order to make your ROM Hacking life easier.
I spent alot of time writting this guide to make it as easy as possible for beginners to read and understand binary and hexadecimal. Some time ago, I saw a thread on a forum discussing how people are starting to lose interest in ROM Hacking because it looks too intimidating and complicated, and how there are not enough good guides out there. So I decided to start writting guides which are super easy to follow and understand. I also decided to include exercises and images, in order to make things easier.
Well, hexadecimal is REALLY importand to know when ROM Hacking. Without knowledge on hexadecimal, you can only go as far as editing a few games from editors that already exist. What if you want to hack a ROM which no one made an editor on? I will show you a small example later on when you get to the hexadecimal part of the guide. What about Binary? While it's no secret that you really don't need binary to ROM Hack(at least the basic stuff), I beleive that learning binary makes learning hexadecimal way easier, that is the reason I included it in this guide.
Note: Binary IS required if you are planning to be a really advanced hacker.
So what is binary? Computers only understand two numbers, and those numbers are 1 and 0. On and Off to be exact, but they are represented as 1 and 0. 0 meaning Off, and 1 meaning On. I can get a lot more technical with this, but this is all you really need to know for now.
Before we continue, I want to make sure you understand decimal first. "Decimal" is the counting system you use in maths. Decimal is a base 10 system, meaning it consists of 10 characters:
0 1 2 3 4 5 6 7 8 9
This is all the characters you use in decimal. So what comes after 09(I added the 0 in order to help you understand)? Of course, you know it's 10, but why is that? There are no more characters to use after 9, so 9 goes back to 0, and 1 is added in front of it, leaving you with 10. I want you to really grasp this way of thinking because it will help you learn binary and hexadecimal way easier.
So why is this needed for binary?
Well, binary is a base 2 system, meaning, as mentioned before, only 2 characters are used. Those characters are 0 and 1. Lets start counting with this system from 0 to 5, and I'll explain while we're counting how binary works. So of course, first we have 0, and then 1. These are the same as decimal.
| Decimal: | 0 | 1 | 2 | 3 | 4 | 5 |
| Binary: | 000 | 001 |
In decimal, after 1 comes 2. What about binary? Think back to the example I gave you earlier with decimal. What happens after 9? 9 goes back to the first character of the system(which in our case is 0) and 1 is added in front. If you think about this in binary, since 1 is our last character of the binary system, it will go back to a 0, while 1 is added to the front, giving us 10b(from now on I will add a "b" at the end of a number to indicate the number is in binary, in order to avoid confusion).
So what comes after 10b(or 2 in decimal)? Well, our last digit is 0, so adding 1 will obviously give as 1, so 3 in binary will be 11b
| Decimal: | 0 | 1 | 2 | 3 | 4 | 5 |
| Binary: | 000 | 001 | 010 | 011 |
So what happens now? We have 11b. If we add 1, the 2nd "1"(11b), it will become a 0, then we shall add 1 to the 1st "1"(11b), so that becomes 0 aswell, and we now simply add a 1 to the front. We now have 100b. Now I want you to go ahead and guess what 5 is in binary. If you guessed, 101, then you are correct. Here is the final table:
| Decimal: | 0 | 1 | 2 | 3 | 4 | 5 |
| Binary: | 000 | 001 | 010 | 011 | 100 | 101 |
That was easy, but what about 6? Well, if we take the "1" on the right (101b) and we add 1, it should become a 0, and then we will need to add 1 to the digit left of it (101b), so that would give us 110, which is 6 in decimal.
Once you've understood the previous part, this should be pretty easy. Let's say we have the binary number 11010010. Take a piece of paper and write it down.
| 1 | 1 | 0 | 1 | 0 | 0 | 1 | 0 |
When we are converting from binary to decimal, we work from right to left. So lets go to the furthest right digit(11010010b), and write 1 underneath it. Now multiply the "1" you wrote earlier with 2, and write that underneath the digit to the left of it(11010010b) Do the same again, get the "2" you just found, and multiply that by 2,which should give you 4, so write 4 underneath the next value(11010010b). Basically, you start with 1, and keep multiplying by 2 for each digit. You should have something like this:
| 1 | 1 | 0 | 1 | 0 | 0 | 1 | 0 |
| 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |

Now go ahead and find all the digits in the binary number which are "1" and take note of the number you have written bellow it:
| 1 | 1 | 0 | 1 | 0 | 0 | 1 | 0 |
| 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
So, we have the numbers: 128, 64, 16 and 2. If you go ahaid and add those numbers, you will get the decimal number! I'ts as easy as that.
128 + 64 + 16 + 2 = 210
Another example: 111011b.
Following the steps from the previous example we get the table:
| 1 | 1 | 1 | 0 | 1 | 1 |
| 32 | 16 | 8 | 4 | 2 | 1 |
Now add all the values which can be found below a "1":
32+16+8+2+1=59
Decimal to Binary is pretty easy, you just need some simple maths. Let's say we want to convert 103 to a binary. Basically for the first step we will keep dividing the number by 2, and get the remainders from the divisions. This is what I mean:
103/2 = 51(.5) remainder 1 (ignore decimal points)
51/2 = 25(.5) remainder 1
25/2 = 12(.5) remainder 1
12/2 = 6 remainder 0
6/2 = 3 remainder 0
3/2 = 1(.5) remainder 1
1/2 = 0(.5) remainder
1
If you don't know how to find the remainder then here is a guide:
https://www.mathsisfun.com/algebra/polynomials-remainder-factor.html
And if you are still having trouble you can always use the modulus operator to work out the remainder. Try going to google and try searching for "the number you are dividing 2 by" mod 2. So for example to find the remainder of 103/2 you would search for "103 mod 2" without the quotation marks. Go ahaid and try it ;) (the windows calculator should also have a modulus operator.)
So now that you have done this, you need to get the remainders from the bottom to upwards, and that would give you 1100111b. And that's all there is to converting Decimal to Binary.
Here are some exercises I put together to help you grasp binary better. Do these on a piece of paper and use the methods from above to help you. Once you finished the exercises, press the spoiler button underneath for the answers.
Now that you understand binary, we can move on to hexadecimal. Here is a table of the characters used in hexadecimal:
| Decimal: | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| Hexadecimal: | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F |
So basically, the numbers 0-9 are the same in hexadecimal, but hexadecimal includes 6 more characters: A, B, C, D, E and F. So 10 in hexadecimal would be Ah, 15 in hexadecimal would be Fh, and 16h would be 10h. This is because, if you remember the previous example from binary, once you run out of characters to use, you add one to the previous character(from 0Fh to 10h), and the current character (10h) goes back to the first character, which is 0h in our case.
Converting from hexadecimal to decimal isn't really that hard. Let's convert F15FFh for example. The first step is to write the position of the number from right to left starting from 0. This is what i mean:
| F | 1 | 5 | F | F |
| 4 | 3 | 2 | 1 | 0 |
Note: Once you get the hang of this, you can skip this step.
Now that we have the position of each number, we will need to use a formula on each of the characters. The formula is the current character times 16 to the power of the position you got earlier: character x 16position
Note: You can also use this formula for binary. Instead of multiplying by 16, you will be multiplying by 2(because it is a base 2 system).
| F | 1 | 5 | F | F |
| 15*164=983040 | 1*163=4096 | 5*162=1280 | 15*161=240 | 15*160=15 |
When you're multiplying characters like "F" use the decimal equivalent(F is equivalent to 15, and E to 14). After you've found the numbers, you add them up, and you get the decimal equivalent!
983040 + 4096 + 1280 + 240 + 15 = 988671
This number actually got pretty long, but I wanted to give you a difficult example so you understand what to do. That's pretty much all there is to converting from hexadecimal to decimal.
Converting decimal to hexadecimal is pretty much the same thing as binary. The process is the same, only this time you are dividing by 16. So let's convert the number 58 to hexadecimal.
58 / 16 = 3(.625) remainder 10(Remember to ignore decimal points)
3/16 = 0(.1875) remainder 3
So now, as we did with binary, read the remainders from bottom up. Remember to convert remainders over 9 to their hexadecimal equivalent. So for 10, that would be Ah. Reading the remainders from bottom up, we get 3Ah. It's as easy as that!
Well, there are a number of reasons you would use hexadecimal for hacking, ranging from making tables, editing text and translating, to level editing. When you are hacking a rom, you will ussually work in a hex editor.
Here is the Pac-Man (NES) Rom loaded in "HxD" Hex Editor:

If you got this far, that means you now understand how to convert to/from binary and hexadecimal. Of course, you won't have to go through this process everytime you are ROM Hacking for every value you find, because it will slow you down. If you know any programming language, it's a good idea to write a program to convert to you(As a hacker, being able to write your own tools is really importand). If you don't, then no worries. The windows calculator program can help you convert hexadecimal and binary values. It will even allow you to do some maths with them.
To start up the calculator, press the start buttons, and search for Calc.exe and press enter. Or you can go to:
Start -> All Programs -> Accessories -> Calculator
Once you have the windows calculator running, you will need to switch it from standard mode to programmer mode. You can do this by clicking on "View" and then choosing "Programmer". You should notice that the layout of the calculator changed.

On the left, notice that there are options for "Hex" "Dec" "Oct" and "Bin".
These stand for:
| Hex | Hexadecimal |
| Dec | Decimal |
| Oct | Octal |
| Bin | Binary |
Octal isn't really used in ROM Haching, but if the need ever arises, you should be able to use the same techniques with hexadecimal and binary to convert. It's octal, so that means it only uses the numbers 0-7.
To convert using the windows calculator program, it's easy. First, select what you want to convert from the options to the left, and enter the number you want to convert.

After that simply choose a different option and it should automatically convert it for you!

It's THAT simple! Also notice the MOD operator I talked about earlier to help you find the remainder:

You can also do some math using hecadecimal, binary and decimal(and octal):

This guide took alot of my time to write, so I hope you enjoyed reading it as much as I enjoyed writing it.(What a cheesy phrase, but hey! it's true!) I hope you learned how to work with binary and hexadecimal, because if you are planning to be a ROM Hacker, it is necessary. This took me around 5 hours to write,in 2 long sittings, so I'm really hoping you make good use of this guide :p
If you still have any questions, feel free to contact me through my blog: https://mevoidroms.wordpress.com/contact/
Or you can find me at the www.romhacking.net forum. My username is mevoid.
Also, let me know for any mistakes I may have made. Thanks!